﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ecreate.Popedom;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Ecreate.Web.popedom.usersearch
{
    public partial class usersearchzero : System.Web.UI.Page
    {
        Ecreate.Popedom.Service.IGroupService groupservice = new Ecreate.Popedom.Service.SpringImpl.GroupServiceImpl();
        Ecreate.Popedom.Service.SpringImpl.UseStateImpl usestate = new Ecreate.Popedom.Service.SpringImpl.UseStateImpl();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                Ecreate.Popedom.tSysuser s = new tSysuser();

                this.ddl_usestate.DataSource = usestate.getAllState();
                this.ddl_usestate.DataTextField = "Name";
                this.ddl_usestate.DataValueField = "Id";
                this.ddl_usestate.DataBind();
                string fields = "prvoincename,cityname,countryname,userId,Username,Tele,Qq,Address,Account,Createdate,Canceldate,useflagname";
                string captions = "省,市,区县,用户账号,用户姓名,电话,QQ号,地址,账号,创建日期,废止日期,用户状态";
                GridHelperSearch search = new GridHelperSearch();
                search.setGridColumn(this.GridView1, fields,captions);
            }

        }

        private string stringname(string value)
        {
            return  value.Replace("1", ".");

        }

        private string stringReplace(string value)
        {


            string result=value.Replace("'", "");
            result = value.Replace("{", "");
            result = value.Replace("}", "");
            result = value.Replace("\"", "");
            return result;
        }
        private string stringReplace(object value)
        {
            return stringReplace(value.ToString());
 
        }
        protected void btn_action_Click(object sender, EventArgs e)
        {
            string jsondata=HtmlHelper.getPostValue(this);
            List<JsonSearch> list = JsonSearch.getList(jsondata);
            string hql = "  select t.*,case t.useflag when 1 then '有效' when 0 then '无效' end as useflagname         ,p.areaname as prvoincename,c.areaname as cityname,country.areaname as countryname from t_Sysuser  t left outer join t_area p on t.provincecode=p.areacode left outer join t_area c on t.citycode=c.areacode left outer join t_area country on t.countrycode=country.areacode   where 1=1   ";
            string pre = " and  t.";
            foreach (JsonSearch js in list)
            {
                if (js.Value != ""&&js.Value!=null)
                {
                    hql += pre + js.Field + js.Operate + "'" + js.Value + "'";
                }
            }
            System.Data.DataTable dt = Ecreate.Data.FactoryDBEngine.GetInstance().GetDataTable(hql);
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
        }




    }
}
